package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.service.AdminStatService;
import com.cskaoyan.market.db.admin.vo.BaseAdminInnerOrderStatVo;
import com.cskaoyan.market.db.admin.vo.RowsGoodsInnerGoodsStatVo;
import com.cskaoyan.market.db.admin.vo.RowsUserInnerUserStatVo;
import com.cskaoyan.market.db.domain.MarketUserExample;
import com.cskaoyan.market.db.mapper.MarketOrderMapper;
import com.cskaoyan.market.db.mapper.MarketUserMapper;
import com.cskaoyan.market.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author 小焦
 * @since 2023/03/21 15:01
 */
public class AdminStatServiceImpl implements AdminStatService {
	/**
	 * {
	 * 		"columns": ["day", "users"],
	 * 		"rows": [{
	 * 			"day": "2019-04-20",
	 * 			"users": 1
	 *                }]* 	}
	 * @return
	 */
	@Override
	public List<RowsUserInnerUserStatVo> user() {
		SqlSession sqlSession = MyBatisUtil.getSession();
		MarketUserMapper userMapper = sqlSession.getMapper(MarketUserMapper.class);
		MarketUserExample example = new MarketUserExample();
		// example.
		List<RowsUserInnerUserStatVo> marketUsers = userMapper.selectUsersTotalAndDayGroupByAddTime();
		sqlSession.commit();
		sqlSession.close();
		return marketUsers;
	}

	@Override
	public List<BaseAdminInnerOrderStatVo> order() {
		SqlSession sqlSession = MyBatisUtil.getSession();
		MarketOrderMapper orderMapper = sqlSession.getMapper(MarketOrderMapper.class);
		MarketUserExample example = new MarketUserExample();
		// example.
		List<BaseAdminInnerOrderStatVo> marketOrders = orderMapper.selectOrderStatGroupByPayTime();
		sqlSession.commit();
		sqlSession.close();
		return marketOrders;
	}

	@Override
	public List<RowsGoodsInnerGoodsStatVo> goods() {
		SqlSession sqlSession = MyBatisUtil.getSession();
		MarketOrderMapper orderMapper = sqlSession.getMapper(MarketOrderMapper.class);
		// MarketUserExample example = new MarketUserExample();
		// example.
		List<RowsGoodsInnerGoodsStatVo> marketGoods = orderMapper.selectGoodsGroupByPayTime();
		sqlSession.commit();
		sqlSession.close();
		return marketGoods;
	}
}
